import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.Cookie;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.net.URLDecoder;



@WebServlet("/b")
public class CookieServeltB extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        Cookie[] cookies = req.getCookies();

       for (Cookie cookie:cookies) {

           String cookieName = cookie.getName();
           String cookieValue = cookie.getValue();
           System.out.println(cookieName + "\t" + cookieValue);
           if ( "uname".equals(cookieName) ) {
               String decodedUsername = URLDecoder.decode(cookie.getValue(), "UTF-8");
               System.out.println(decodedUsername);
           }
       }

    }

}
